package pers.lan.linkedlist;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/9/8 11:14 AM
 */
public class LC_83 {

    public static void main(String[] args) {
        System.out.println(
                new LC_83()
                        .deleteDuplicates(ListNode.build(new int[]{
                                1, 1, 2, 3, 4, 4, 5
                        }))
        );
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head != null) {
            ListNode p = head;
            ListNode q = p.next;
            while (q != null) {
                if (p.val != q.val) {
                    p.next = q;
                    p = p.next;
                }
                q = q.next;
            }
            p.next = null;
        }

        return head;
    }
}
